# = test.forum.11.rb - Forum , Forum SecureRSS Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# Here we test the functionality for Secure Syndication and verify that it is secured RSS
# 
#
require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
    
	class TC_ForumSecureRss_test < Test::Unit::TestCase
    
    def startup      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
      
      ie.link(:id, /loginButton$/).click
      
      ie.link(:text, 'Forums').click
      
      assert(ie.link(:text, 'Sample Forum').exists?)
      ie.link(:text, 'Sample Forum').click
	  end
    
    def test_05_verifyDropdownListsOnForumPage
      assert(ie.select_list(:id, /SortBy$/).exists?)
      assert(ie.select_list(:id, /SortOrder$/).exists?)
      assert(ie.select_list(:id, /DateFilter$/).exists?)
    end
    
    def test_06_verifyButtonsOnForumPage
      assert(ie.button(:id, /ApplyTemp$/).exists?)
    end
    
    def test_07_verifyFieldsOnForumPage
      assert(ie.text_field(:id, /TitleBarSearchText$/).exists?)
    end
    
    def test_08_navigateToRssFeed
      #assert(ie.link(:id , 'RSS Available').exists?)
      #ie.link(:text, 'RSS Available').click
      assert(ie.image(:src,  $SITE_URL +'utility/images/rss.gif').exists?)
      ie.image(:src,  $SITE_URL +'utility/images/rss.gif').click
    end
    
    def test_09_verifyRssContents
      assert(ie.contains_text("What is RSS"))
      assert(ie.contains_text("Sample Forum"))
      assert(ie.contains_text("Published"))
      assert(ie.link(:text, 'Sample Forum Post').exists?)
    end
    
    def test_14_verifyControlPanel
      ie.goto($SITE_URL)
      ie.refresh
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))      
    end
    
    def test_15_navigateToRssSettings
      assert(ie.link(:text, 'Administration').exists?)
      ie.link(:text, 'Administration').click
      ie.goto($SITE_URL + 'controlpanel/Settings/Rss.aspx')      
    end
    
    def test_16_verifyRssPageLinks
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
    end
    
    def test_17_verifyRadioButtonsOnRssPage
      assert(ie.radio(:id, /SecureRss_0$/).exists?)
      assert(ie.radio(:id, /SecureRss_1$/).exists?)
      assert(ie.radio(:id, /RssSearch_0$/).exists?)
      assert(ie.radio(:id, /RssSearch_1$/).exists?)
    end
    
    def test_18_enableSecureSyndication
      assert(ie.radio(:id, /SecureRss_0$/).exists?)
      ie.radio(:id, /SecureRss_0$/).set
      
      assert(ie.link(:id, /SaveButton$/).exists?)
      ie.link(:id, /SaveButton$/).click
    end
    
    def test_19_testRssFeed
      ie.goto($SITE_URL)
      
      ie.link(:text, 'Forums').click
      
      assert(ie.link(:text, 'Sample Forum').exists?)
      ie.link(:text, 'Sample Forum').click
      
      test_08_navigateToRssFeed
      test_09_verifyRssContents
    end
    
  end